package android.coocoo.models;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.coocoo.common.Const;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

public class TaskInfo implements Parcelable{
	
	private static int count = 0;
	
	public TaskInfo(Parcel in) {
	      readFromParcel(in);
	}
	
	public TaskInfo() {
		super();
		this.id = count;
		this.count++;
		this.title = Const.DefaultValue.DEFAULT_TASKS_TITLE;
		this.categoryId = Const.DefaultValue.DEFAULT_TASKS_CATEGORY_ID;
		this.description = Const.DefaultValue.DEFAULT_TASKS_DESCRIPTION;
		this.priority = Const.DefaultValue.DEFAULT_TASKS_PRIORITY;
		this.hasAlarm = Const.DefaultValue.DEFAULT_TASKS_HAS_ALARM;
		this.startTime = (Date) Const.DefaultValue.DEFAULT_TASKS_START_TIME.clone();
		this.before = Const.DefaultValue.DEFAULT_TASKS_BEFORE;
		this.vibration = Const.DefaultValue.DEFAULT_TASKS_VIBRATION;
		this.ringtone = Const.DefaultValue.DEFAULT_TASKS_RINGTONE;
	}

	private int id;
	private String title;
	private int categoryId;
	private String description;
	private int priority;
	private boolean hasAlarm;
	private Date startTime;
	private int before;
	private boolean vibration;
	private String ringtone;

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setHasAlarm(boolean hasAlarm) {
		this.hasAlarm = hasAlarm;
	}

	public boolean isHasAlarm() {
		return hasAlarm;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public int getPriority() {
		return priority;
	}

	public void setBefore(int before) {
		this.before = before;
	}

	public int getBefore() {
		return before;
	}

	public void setVibration(boolean vibration) {
		this.vibration = vibration;
	}

	public boolean isVibration() {
		return vibration;
	}

	public void setRingtone(String ringtone) {
		this.ringtone = ringtone;
	}

	public String getRingtone() {
		return ringtone;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
//		private int id;
		dest.writeInt(this.getId());
//		Log.e("pass_flag","add ID: " + this.getId());
//		private String title;
		dest.writeString(this.getTitle());
//		Log.e("pass_flag","add tt");
//		private String categoryId;
		dest.writeInt(this.getCategoryId());
//		Log.e("pass_flag","add CateID");
//		private String description;
		dest.writeString(this.getDescription());
//		Log.e("pass_flag","add des");
//		private int priority;
		dest.writeInt(this.getPriority());
//		Log.e("pass_flag","add prio");
//		private boolean hasAlarm;
		if (this.isHasAlarm())
			dest.writeByte((byte) 1);
		else
			dest.writeByte((byte) 0);
//		Log.e("pass_flag","add alarm");
//		private Date startTime;
		dest.writeSerializable(startTime);
//		SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy kk:mm");
//		String _strDate = df.format(this.getStartTime());
//		dest.writeString(_strDate);
////		dest.writeSerializable(this.getStartTime());
//		Log.e("pass_flag","add start: " + _strDate);
//		Log.e("pass_flag","add end");
//		private int before;
		dest.writeInt(this.getBefore());
//		Log.e("pass_flag","add bf");
//		private boolean vibration;
		if (this.isVibration())
			dest.writeByte((byte) 1);
		else
			dest.writeByte((byte) 0);
//		Log.e("pass_flag","add vib");
//		private String ringtone;
		dest.writeString(this.getRingtone());
//		Log.e("pass_flag","add ring");
	}
	
	public static final Parcelable.Creator<TaskInfo> CREATOR
		= new Parcelable.Creator<TaskInfo>() {
			public TaskInfo createFromParcel(Parcel source) {
				return new TaskInfo(source);
			}
			public TaskInfo[] newArray(int size) {
				return new TaskInfo[size];
			}
		};

	private void readFromParcel(Parcel in) {
//		  private int id;
		this.id = in.readInt();
//		Log.e("pass_flag","read ID");
//		  private String title;
		this.title = in.readString();
//		Log.e("pass_flag","read tt");
//		  private String categoryId;
		this.categoryId = in.readInt();
//		Log.e("pass_flag","read cateID");
//		  private String description;
		this.description = in.readString();
//		Log.e("pass_flag","read des");
//		  private int priority;
		this.priority = in.readInt();
//		Log.e("pass_flag","read prio");
//		  private boolean hasAlarm;
		byte _hasAlarm = in.readByte();
		if (_hasAlarm == 1)
			this.hasAlarm = true;
		else
			this.hasAlarm = false;
//		Log.e("pass_flag","read alarm");
//		  private Date startTime;
//		String _strDate = in.readString();
//		try {
//			this.startTime = new SimpleDateFormat("MM/dd/yy kk:mm").parse(_strDate);
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		this.startTime = (Date) in.readSerializable();
//		Log.e("pass_flag","read start");
//		Log.e("pass_flag","read end");
//		  private int before;
		this.before = in.readInt();
//		Log.e("pass_flag","read bf");
//		  private boolean vibration;
		byte _isVibration = in.readByte();
		if (_isVibration == 1)
			this.vibration = true;
		else
			this.vibration = false;
//		Log.e("pass_flag","read vib");
//		  private String ringtone;
		this.ringtone = in.readString();
//		Log.e("pass_flag","read ring");
	}
}
